<?php

namespace App\Models;

class Config extends Base
{
    protected $table = 'configs';
    const SITE_KEY = 'site';

    public static function getDiscount() {
        return Config::where('key', 'discount')->value('value') / 100;
    }

    public static function getCommission() {
        return Config::where('key', 'commission')->value('value') / 100;
    }

    public static function getVipCommission() {
        return Config::where('key', 'vip_commission')->value('value') / 100;
    }

    public static function getRecCookbookCommission() {
        return Config::where('key', 'rec_cookbook_commission')->value('value') / 100;
    }

    public static function getDarenAmount() {
        return Config::where('key', 'daren_amount')->value('value');
    }

    public static function getAdvUnit() {
        return Config::where('key', 'adv_unit')->value('value');
    }

    public static function getMerchantCommission($order_id) {
        $order = Order::find($order_id);
        if ($order->rec_merchant_id) {
            return 1 - self::getRecCookbookCommission() - self::getCommission();
        } else {
            return 1 - self::getCommission();
        }
    }


}
